<?php
namespace GuessSong\Controller;
use Common\Controller\GuessSongController;
class TestController extends GuessSongController {


    public function updatequersions(){

        return 1;

//        $where['song_quersion_id'] = array('GT',599);
//        $quersion = M('SongQuersion')->field('song_quersion_id,puzzle1,puzzle2,puzzle3,puzzle4,songa,songb')->where($where)->select();
//
//
//        $data = array();
//
//        foreach ($quersion as $value){
//
//            $data = array(
//                'a'=>$value['puzzle1'],
//                'b'=>$value['puzzle2'],
//                'c'=>$value['puzzle3'],
//                'd'=>$value['puzzle4'],
//            );
//
//            shuffle($data);
//            $songa = 'music2/'.$value['songa'];
//            $songb = 'music2/'.$value['songb'];
//
//            $arr = array(
//                'puzzle1'=>$data[0],
//                'puzzle2'=>$data[1],
//                'puzzle3'=>$data[2],
//                'puzzle4'=>$data[3],
//                'songa'=>$songa,
//                'songb'=>$songb,
//                'sort'=>$value[song_quersion_id],
//                'createtime'=>time(),
//                'updatetime'=>time(),
//            );
//
//            M('SongQuersion')->where(array('song_quersion_id'=>$value[song_quersion_id]))->save($arr);

     //   }

    }


    public function test()
    {

        return 1;

        $quersion = M('SongQuersion')->field('song_quersion_id,puzzle1,puzzle2,puzzle3,puzzle4,songa,songb')->select();


        $data = array();

        foreach ($quersion as $value) {

            $data = array(
                'a' => $value['puzzle1'],
                'b' => $value['puzzle2'],
                'c' => $value['puzzle3'],
                'd' => $value['puzzle4'],
            );

            shuffle($data);


            $arr = array(
                'puzzle1' => $data[0],
                'puzzle2' => $data[1],
                'puzzle3' => $data[2],
                'puzzle4' => $data[3],
                'sort' => $value[song_quersion_id],
                'createtime' => time(),
                'updatetime' => time(),
            );

            M('SongQuersion')->where(array('song_quersion_id' => $value[song_quersion_id]))->save($arr);

        }

    }


    public function starqustion(){

        return 1 ;
        $quersion = M('star_question')->field('star_question_id,puzzle1,puzzle2,puzzle3')->select();


        $data = array();
        $i=0;
        foreach ($quersion as $value) {
        $i++;
            $data = array(
                'a' => $value['puzzle1'],
                'b' => $value['puzzle2'],
                'c' => $value['puzzle3'],
            );

            shuffle($data);

            $arr = array(
                'puzzle1' => $data[0],
                'puzzle2' => $data[1],
                'puzzle3' => $data[2],
                'sort'=>$i,
            );

            M('star_question')->where(array('star_question_id' => $value[star_question_id]))->save($arr);

        }

    }

    public function test2(){

        return 1;
        exit;
        $where['song_quersion_id'] = array('LT',600);
        $quersion = M('SongQuersion')->field('song_quersion_id,songa,songb,album')->where($where)->select();

        foreach ($quersion as $value) {


            $songa = 'song/'.$value['album'].'/'.$value['songa'];
            $songb = 'song/'.$value['album'].'/'.$value['songb'];

            $arr = array(
              'songa'=>$songa,
               'songb'=>$songb,
            );

            M('SongQuersion')->where(array('song_quersion_id' => $value[song_quersion_id]))->save($arr);

        }
    }

    public function test3(){

        $appid ="wx71e7a983a194c512";
        $session_key = "HdpwosimIWtu4vwTJVNTtg==";

        $rawData = '{"nickName":"undefined","gender":1,"language":"zh_CN","city":"金华","province":"浙江","country":"中国","avatarUrl":"https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTJwQNibN14h9dZIs5QYh7vlKEUKGa1p6FIwNCDlmJ7Rea748sD9oFib8Y1Yt6LnpW8QPBOD8OiaYkAyg/132"}';
        $signature = "68f771ddffabee5209d3e716bb369f25beac1332";
        //验证signature
        $sign=sha1($rawData.$session_key);

        if($sign!=$signature) echo 1;

        $encryptedData = "8gaQSm3Hgga4KJo5llyVfweABFMxTe2t/PPt0b6Tw3kLsAiutqodpSs+8V/34dlfDUW/GgSDv3GmdLpLUrLK+1Ecfcgc0+Ie47hALaF2W7bELUybPJAj79UPm1QP6hy8mrGiV82F78sZAz0LsJNBXguLKYQlaq6xjL+iFz/kN+t0H5289eOy3aI5TBf5kskd/FiRr9L2dumAuA8o8RjK5LwUhmuChcdFW/gXTBKy9bptb5c+LmduVItG1LHj0wKPRGMX5Ep9fpiBPxHYpUK4CEck7PwXZJ12vVonuJUxh0JI5JbAENLPTkC6nCvBYH/DoorFTM3Ek2dU8R19NMBsTHWKLS1gQLyjSGciivuI4gW8u72tu0uHObaznblr2oWkpFQP6Zdwq90t2lvANcZv/7uRiYFCrD0Pp3w669AF7ae3+oGKEKPZkCNEnJlGrNDzgb7VbMEDSS9ptVScoSHsR0P9VhSApJUSn/V0ue6PsaM=";
        $iv = "+oTkeKfnyS/HyAPuyRJpYw==";
        $decryptData = "";
        $data = "";
        $pc = new \aes\WXBizDataCrypt($appid, $session_key);
        $errCode=$pc->decryptData($encryptedData,$iv,$data);

        var_dump($errCode);

    }


    public function test4(){

        $info = $_POST['info'];
        $a = $info;
        //$a = substr($a,1);
        //$a= substr($a, 0, -1);
       $a= json_decode($a,true);

        echo json_encode($a['nickName']);
    }


    public function test5(){

        exit;
        S('song_quersion',null);

    }

}
